﻿using AutoMapper;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;

namespace Business.WriteAPI.Application.Machinings
{
    public class PackUpdRequestHandler : IRequestHandler<PackUpdRequestModel, APIResult>
    {
        private readonly IBaseRepository<PackeMaterial> baseRepository;
        private readonly IMapper mapper;
        public PackUpdRequestHandler(IBaseRepository<PackeMaterial> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(PackUpdRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.UpdSuccess;
            result.Msg = "编辑成功";

            PackeMaterial slaughte = mapper.Map<PackeMaterial>(request);
            baseRepository.Update(slaughte);

            return Task.FromResult(result);
        }
    }
    public class PackUpdRequestModel:IRequest<APIResult>
    {
        public int Id { get; set; }
        public string ProductCode { get; set; }
        public string ProductionBatch { get; set; }
        public string Creator { get; set; }
        public DateTime CreateTime { get; set; }
    }
}
